<template>
  <ul class="switches" @click.stop>
    <li class="switches-item" v-for="(item,index) in switches"
        :key="'switch'+index" :class="{'active': currentIndex===index}" @click="select(index)">
      <span>{{item.name}}</span>
    </li>
  </ul>
</template>

<script>
export default {
  name: 'switches',
  props: {
    switches: {
      type: Array,
      default: () => []
    },
    currentIndex: {
      type: Number,
      default: 0
    }
  },
  methods: {
    select (index) {
      this.$emit('select', index)
    }
  }
}
</script>

<style lang="less" scoped>
  @import '~common/css/variable';
  .switches {
    display: flex;
    align-items: center;
    width: 240px;
    margin: 0 auto;
    border: 1px solid @color-highlight-background;
    border-radius: 5px;
    box-sizing: border-box;
    .switches-item {
      flex: 1;
      padding: 8px;
      text-align: center;
      font-size: @font-size-medium;
      color: @color-text-d;
      &.active {
        background-color: @color-highlight-background;
        color: @color-text;
      }
    }
  }
</style>
